import { getDynamicRoutes } from "@/router/config.js";

export default () => {
  const storageTokenKey = "__user_token__";

  const state = reactive({
    authList: [],
    token: "",
    userInfo: {},
    department: {},
  });

  const methods = {
    login: () => {
      const router = useRouter();

      state.token = "123";
      state.authList = ["3"];

      console.log("??? ", router);

      useRouter().addRoutes(getDynamicRoutes(state.authList));
      useRouter().push("/");
    },
  };

  watchEffect(() => window.localStorage.setItem(storageTokenKey, state.token));

  return {
    ...state,
    ...methods,
  };
};
